﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CanSWAT.SWAT
{
    /// <summary>
    /// Corresponding to one single parameter in all input files. 
    /// </summary>
    /// <remarks>
    /// The formate of SWAT single parameter
    /// <para>[parameter value] | [Parameter Name] : [parameter description]</para>
    /// </remarks>
    class SingleParameter
    {
        private double _value = -99.0;
        private string _description = "";
        private string _name = "";

        private static char[] SEPERATOR = { '|', ':' };

        /// <summary>
        /// initialize using a line in parameter file
        /// </summary>
        /// <param name="line">line is a line in parameter file</param>
        public SingleParameter(string line)
        {
            string[] p = line.Split(SEPERATOR);
            double.TryParse(p[0], out _value);

            if (p.Length >= 2)
                _name = p[1];

            if (p.Length > 2)
                _description = p[2];
            else
                _description = _name;
        }

        public SingleParameter(string name, string description, double value)
        {
            _value = value;
            _name = name;
            _description = description;
        }

        public double Value
        {
            get { return _value; }
            set { _value = value; }
        }

        public string Description
        {
            get { return _description; }
        }

        public override string ToString()
        {
            return string.Format("{0}    | {1} : {2}",
                _value.ToString("0.#######", System.Globalization.CultureInfo.InvariantCulture).PadLeft(16),
                _name, _description);
        }
    }
}
